package com.ccm.demo.shiro;

import com.ccm.demo.dao.SysRoleMapper;
import com.ccm.demo.dao.SysUserMapper;
import com.ccm.demo.model.SysRole;
import com.ccm.demo.model.SysUser;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class UserInfoService{

	@Resource
	private SysUserMapper sysUserMapper;
	@Resource
	private SysRoleMapper sysRoleMapper;

	public SysUser findByUsername(String s){
		SysUser sysUser = sysUserMapper.selectByUsername(s);
		if (sysUser == null) {
			return sysUser;
		}
		List<SysRole> roles = sysRoleMapper.selectByUserId(sysUser.getSysId());
		sysUser.setRoles(roles);
		return sysUser;
	}
}
